﻿@using System.Drawing
@using DeliveryPlus.Web.Classes.Enums
@using DeliveryPlus.Web.DAL
@model DeliveryPlus.Web.DAL.Entities.Dishe

@{
    ViewBag.Title = String.Format("{0} | {1} | Заведения",Model.Title,Model.Cafe.Title);
    Layout = "../Shared/Layout.cshtml";
    var cafe = Model.Cafe;
    var allTypes = cafe.Dishes.Select(d => d.TypeId).ToArray();
    var types = new DeliveryPlusDataContext().DishTypes.Where(dt => allTypes.Contains(dt.Id));
}

<div id="page-dish" class="page">
    <div class="page-title">
        <img src="~/Content/images/cafe/title.png" />
    </div>
    <div class="row" id="first-row">
        <div class="left">
            <ul>
                <li><a href="/cafe">Заведения</a></li>
                <li class="active"><a href="/cafe/@cafe.Id/dishes">@cafe.Title</a></li>
            </ul>
            <img src="~/Content/images/dishes/sep-small.png" />
        </div>
        <div class="separator">
        </div>
        <div class="right">
            <div class="title">
                @cafe.Title
            </div>
            <img src="~/Content/images/dishes/sep-large.png" />
        </div>
    </div>
    <div class="row" id="second-row">
        <div class="left">
            <div class="wrap">
                @foreach (var group in types.GroupBy(t => t.GroupName))
                {
                    <div class="types-group">
                        @if (!String.IsNullOrEmpty(group.Key))
                        {
                            <div class="group-title">
                                @group.Key
                            </div>
                        }
                        <ul class="type-filter">
                            @foreach (var type in group)
                            {
                                <li @(Model.TypeId == type.Id ? "class=active":"")><a href="/cafe/@cafe.Id/dishes?type=@type.Id">@type.Title</a></li>    
                            }
                        </ul>
                    </div>
                }
                <p style="margin: 5px">
                    <a href="/cafe/@cafe.Id/dishes">Все блюда</a>
                </p>    
            </div>
            <img src="~/Content/images/dishes/sep-small.png" />
        </div>
        <div class="separator">
        </div>
        <div class="right">
            <div id="dishes">
                <div class="dish-info">
                    <div class="dish-image">
                        @if (!String.IsNullOrEmpty(Model.Photo))
                        {
                            <img src="/Files/Dish/@Model.Photo" alt="@Model.Title, @cafe.Title, Хабаровск"/>
                        }
                    </div>
                    <div class="dish-desc">
                        <div class="dish-title">
                            @Model.Title
                            @if (!String.IsNullOrEmpty(Model.Weight))
                            {
                                @String.Format("({0} грамм)",Model.Weight)
                            }
                        </div>
                        <div class="dish-price">
                            @String.Format("{0:c}",Model.Price)
                        </div>
                        <div class="dish-order">
                            <a href="javascript:orderDish(@Model.Id);" title="Добавить в заказ" id="order-btn">
                                
                            </a>
                        </div>
                        <div class="dish-desc-content">
                            @Html.Raw(@Model.Description)
                        </div>
                    </div>
                </div>
            </div>
            <img src="~/Content/images/dishes/sep-large.png" />
        </div>
    </div>
    <div class="row" id="third-row">
        <div class="left">
            <div id="address">
                @Html.Raw((cafe.Address ?? "").Replace("\r","<br/>").Replace("\n","<br/>"))
            </div>
            <img src="~/Content/images/dishes/sep-small.png" />
        </div>
        <div class="separator">
        </div>
        <div class="right">
            <div id="desc">
                @Html.Raw(@cafe.Description)    
            </div>
            <img src="~/Content/images/dishes/sep-large.png" />
        </div>
    </div>
</div>
<script type="text/javascript">
    $(document).ready(function() {
        $(window).resize(function () {
            // Second
            var left = $("#second-row .left .wrap").height();
            var right = $("#second-row .right #dishes").height();
            if (left >= right) {
                $("#second-row .separator").height(left);
                $("#dishes").height(left);
            } else {
                $("#second-row .separator").height(right);
                $("#second-row .left .wrap").height(right);
            }
            
            // Third
            left = $("#third-row .left #address").height();
            right = $("#third-row .right #desc").height();
            if (left >= right) {
                $("#third-row .separator").height(left);
                $("#desc").height(left);
            } else {
                $("#third-row .left #address").height(right);
                $("#third-row .separator").height(right);
            }
        }).resize();
    });
</script>